snippet @c "copyright (@c)"
// Written `!v strftime("%Y")`
$0
endsnippet

snippet d "#define (d)" !b
#define $1
endsnippet

snippet i "#include (i)" !b
#include "${1:`!p snip.rv = snip.basename + '.h'`}"
endsnippet

snippet I "#include <> (I)" !b
#include <$1>
endsnippet

snippet func "function (func)"
$1 $2($3) {
  $0
}
endsnippet

snippet enum "Enumeration (enum)"
enum $1 {
  $0
};
endsnippet

snippet td "Typedef (td)"
typedef $1 $2;
endsnippet

snippet for "for int loop (for)"
for (${1:size_t} ${2:i} = 0; $2 < ${4:count}; ${3:++$2}) {
  ${VISUAL}$0
}
endsnippet

snippet while "while loop (while)"
while ($1) {
  ${VISUAL}$0
}
endsnippet

snippet do "do...while loop (do)"
do {
  ${VISUAL}$0
} while($1);
endsnippet

snippet main "main() (main)" !b
int main(int argc, char const *argv[]) {
  $0
  return 0;
}
endsnippet

snippet if "if .. (if)"
if ($1) {
  ${VISUAL}$0
}
endsnippet

snippet ife "if .. else (ife)"
if ($1) {
  $2
} else {
  $3
}
endsnippet

snippet ifel "if .. else if (ifel)"
if ($1) {
  $2
} else if ($3) {
  $4
}
endsnippet

snippet st "struct (st)"
struct $1 {
	$0
};
endsnippet

snippet tst "struct (tst)"
typedef struct {
	$0
} $1;
endsnippet

snippet once "ifndef guard (once)" !b
#ifndef ${1:`!p
if not snip.c:
  import random, string
  name = re.sub(r'[^A-Za-z0-9]+','_', path).upper()
  snip.rv = ('%s' % (name)).upper()
else:
  snip.rv = snip.c`}
#define $1

${0}

#endif  // $1

endsnippet
